package com.gyx.metaldesigndemo.coordinator;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.gyx.metaldesigndemo.R;

public class CollapsingToolBarLayoutActivity extends AppCompatActivity {
    private Toolbar toolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collapsing_app_bar_layout);
        toolbar= (Toolbar) findViewById(R.id.toolbar);
        initToolBar();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_collapsingtoolbar_activity,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.menu3:
                Toast.makeText(this,"menu3",Toast.LENGTH_SHORT).show();
                break;
            case R.id.menu4:
                Toast.makeText(this,"menu4",Toast.LENGTH_SHORT).show();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    private void initToolBar(){
        toolbar.setTitle("你好");
//        toolbar.setLogo(R.mipmap.ic_launcher);
//        toolbar.setSubtitle("我好");

        toolbar.setNavigationIcon(R.mipmap.ic_launcher);

        setSupportActionBar(toolbar);


        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }
}
